﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Input;
using System.Collections.ObjectModel;
using Samurai.Infrastructure;

namespace Samurai.Client.DataContexts
{
    public class RefreshRepositoriesCommand : ICommand
    {
        private ObservableCollection<Repository> _repositories;

        public RefreshRepositoriesCommand(ObservableCollection<Repository> repositories)
        {            
            this._repositories = repositories;
        }

        public bool CanExecute(object parameter)
        {
            return true;
        }

        public event EventHandler CanExecuteChanged;

        public void Execute(object parameter)
        {
            Repository[] newRepositories = DAL.Manager.Instance.GetNewRepositories(_repositories.ToArray());

            foreach (var repository in newRepositories)
            {
                _repositories.Add(repository);
            }
        }
    }
}